import { Component } from 'react'
import { View, } from '@tarojs/components'
import { AtButton, AtTextarea } from 'taro-ui'
import { observer, inject } from 'mobx-react'
import Taro from '@tarojs/taro'
import './index.less'

const PAGE_SIZE = 10;

@inject('store')
@observer
export default class Suggest extends Component {
  state = {
    text: '',
  }

  handleChange = (text) => {
    this.setState({
      text
    })
  }

  handleSubmit = async () => {
    const { id } = this.props.store.userInfo
		const { text } = this.state;
    if (!text) {
      Taro.showToast({
				title: '请输入你的建议',
				icon: 'none',
				duration: 2000
			})
      return;
    }

		const params = {
			accountId: id,
      text
		};

		const { success, data, msg } = await Taro.request({
			method: 'post',
			url: '/api/suggest',
			data: params
		})

		if (success) {
			Taro.showToast({
				title: '提交成功',
				icon: 'success',
				duration: 2000
			})
      // Taro.navigateBack();
		}
	}

  render () {

    return (
      <View className='suggest-page'>
        <AtTextarea
          value={this.state.text}
          onChange={this.handleChange}
          maxLength={300}
          placeholder='请输入你的建议...'
          height={700}
        />
        <View className='submit-footer-btn' onClick={this.handleSubmit}>
          提交
        </View>
      </View>
    )
  }
}